<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$postdata=get_postdata();
$chatmsg = trim($postdata['msg']);
$setting=core_setting('site');
if(empty($setting['isjyrobot']) || empty($setting['jyrobotkey'])){
	$return['error'] = 1;
	$return['msg'] = '没有开启机器人！';
	exi($return);
}
if(empty($chatmsg)){
	$return['error'] = 1;
	$return['msg'] = '请输入对话内容！';
	exi($return);
}
if(empty($postdata['chatid'])){
	$chatid = cfc('syskefu')->getchatid();
}
$resmsg = cfc('syskefu')->jinyunrobot($chatmsg);
if(!$resmsg){
	$return['error'] = 1;
	$return['msg'] = '机器人没有返回数据！';
	exi($return);
}else{
	$msg = $resmsg;
}
$getmid = intval($postdata['getmid']);
$siteinfo=pdo_get('core_accounts',array('uniacid'=>$_SESSION['uniacid']),array('title','desc','logo','groupid','credit2'));
$setdata =array(
	'nickname' => $siteinfo['title']?$siteinfo['title']:'匿名用户',
	'logo' => $siteinfo['logo'],
	'createtime'=>TIMESTAMP,
	'msg'=>$chatmsg,
	'uniacid' => $_SESSION['uniacid'],
	'chatid' => intval($postdata['chatid']),
	'type' =>1,
);
$robotdata =array(
	'nickname'=>'机器人',
	'createtime'=>TIMESTAMP +1,
	'msg'=>$msg,
	'uniacid' => $_SESSION['uniacid'],
	'chatid' => intval($postdata['chatid']),
	'type' =>1,
);
pdo_insert('core_kefu_chatlog',$robotdata);
pdo_insert('core_kefu_chatlog',$setdata);
$return['error'] = 0;
$return['msg'] = $msg;
exi($return);